package com.zhuoyue.biz.core.api.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhuoyue.biz.core.api.domain.AppUserDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author wjming
 * @ClassName: AppUserDao
 * @Description: 用户底层数据
 * @Date 2021-07-08 13:33
 */
public interface AppUserDao extends BaseMapper<AppUserDO> {

    /**
     * 选择性修改APP用户信息
     *
     * @param appUser
     * @return
     */
    int updateAppUserSelective(AppUserDO appUser);


    /**
     * 查询家庭的子账号用户
     *
     * @param homeId
     * @return
     */
    List<AppUserDO> selectChildUserList(String homeId);

    /**
     * 查询用户信息通过网关
     * @param gatewayMac
     * @return
     */
    List<AppUserDO> selectAppUserByGatewayMac(String gatewayMac);

    /**
     * 根据appUserId获取昵称
     *
     * @param id
     * @return
     */
    @Select("SELECT nick_name FROM tbl_app_user WHERE id = #{id}")
    String selectNameById(@Param("id") String id);

    /**
     * 根据openid查询用户信息
     *
     * @param query
     * @return
     */
    AppUserDO selectAppUserByOpenid(AppUserDO query);

    /**
     * 清空openid
     *
     * @param query
     * @return
     */
    int updateClearOpenId(AppUserDO query);

    /**
     * 修改openid
     *
     * @param query
     * @return
     */
    int updateOpenIdById(AppUserDO query);

    /**
     * 取消分享时通过用户的homeId来获取主人的sourceId
     *
     * @param homeId
     * @return
     */
    AppUserDO selectMasterSourceId(String homeId);

    /**
     * 退出登陆,清空用户信息
     *
     * @param id
     * @return
     */
    @Update("UPDATE tbl_app_user SET token=NULL,source_id=NULL,modify_time=NOW() WHERE id=#{id}")
    int updateExit(@Param("id") String id);

}
